package com.buli.blmall.admin.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.buli.blmall.admin.system.entity.SysMenu;
import org.springframework.web.bind.annotation.*;
import com.buli.blmall.admin.system.service.SysMenuService;
import com.buli.blmall.admin.system.vo.SysMenuVO;
import com.buli.blmall.admin.base.BaseController;
import com.buli.blmall.admin.common.response.Result;
import java.util.List;
import lombok.AllArgsConstructor;


/**
 * <p>
 * 菜单 控制器
 * </p>
 *
 * @author buli
 * @since 2025-02-27
 */
@RestController
@RequestMapping("system/sys_menu")
@AllArgsConstructor
public class SysMenuController extends BaseController {

    private SysMenuService sysMenuService;

    /**
     * 分页查询菜单
     * @param sysMenuVo
     * @param current
     * @param size
     * @return
     */
    @GetMapping("/page")
    public Result<IPage<SysMenu>> page(@ModelAttribute SysMenuVO sysMenuVo,
                                       @RequestParam(defaultValue = "1") Integer current,
                                       @RequestParam(defaultValue = "10") Integer size) {
        IPage<SysMenu> page = sysMenuService.queryPageWithCondition(current, size, sysMenuVo);
        return Result.success(page);
    }

    /**
     * 查询菜单详情
     *
     * @param id 菜单ID
     */
    @GetMapping("/{id}")
    public Result<SysMenuVO> getSysMenu(@PathVariable Long id) {
        return Result.success(sysMenuService.info(id));
    }

    /**
     * 查询菜单集合
     *
     * @param sysMenuVo
     */
    @GetMapping("/list")
    public Result<List<SysMenuVO>> listSysMenu(SysMenuVO sysMenuVo) {
        return Result.success(sysMenuService.queryList(sysMenuVo));
    }

    /**
     * 添加菜单
     * @param sysMenuVo
     */
    @PostMapping("/add")
    public Result<Boolean> addSysMenu(@RequestBody SysMenuVO sysMenuVo) {
        return Result.success(sysMenuService.add(sysMenuVo));
    }

    /**
     * 修改菜单
     * @param sysMenuVo
     */
    @PutMapping("/edit")
    public Result<Boolean> editSysMenu(@RequestBody SysMenuVO sysMenuVo) {
        return Result.success(sysMenuService.edit(sysMenuVo));
    }

    /**
     * 删除菜单
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public Result<Boolean> removeSysMenu(@PathVariable Long id) {
        return Result.success(sysMenuService.removeById(id));
    }

}

